<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Login extends CI_Controller {

	//构造函数
    function __construct(){
        parent::__construct();
        //载入Admin模型
        $this->load->model("Member_model");
    }
	public function index()
	{
        if (!$_POST) {
            $this->load->view('login');
        }else{
            //执行登录
            $username=trim($this->input->post('username'));
            $password=md5($this->input->post('password'));
            $res_login=$this->Member_model->login($username,$password);
            if ($res_login) {
                $_SESSION['admin']['id']=$res_login->id;
                $_SESSION['admin']['username']=$res_login->username;
                $_SESSION['admin']['role']=$res_login->role;
                redirect("Home/index");
            }else{
            	echo'密码错误';
            }
        }       
	}	
	// public function findpass(){
 //        $this->load->model("Sendsms_model");
 //        if (!$_POST) {
 //            $this->load->view('findpass');
 //        }else{
 //            $phone=$this->input->post('phone');
 //            $res_phone=$this->Member_model->check_register($phone);
 //            if (!$res_phone) {
 //                $data['data']=null;
 //                $data['code']=500;
 //                $data['message']='该手机号未注册';
 //                echo json_encode($data);
 //                exit;
 //            }
 //            //发送短信验证码
 //            $yzm=rand('100000','999999');
 //            $send_res=$this->Sendsms_model->sendms('28国际期货','SMS_82495004',$phone,Array("yzm"=>$yzm),"123");
 //            if ($send_res->Code != 'OK') {
 //                $data['message']='手机验证码发送失败,请稍后再试';
 //                echo json_encode($data);
 //                exit;
 //            }
 //            $_SESSION['user']['passyzm']=$yzm;
 //            $_SESSION['user']['phone']=$phone;
 //            $data['data']=null;
 //            $data['code']=0;
 //            echo json_encode($data);
 //            exit;
 //        }

 //    }  
}
